const observer = new MutationObserver(mutationCallback);
let counter = 1;
const textNode = document.createTextNode(counter);
observer.observe(textNode, { characterData: true, characterDataOldValue: true });

function mutationCallback(mutations) {
    console.log(mutations[0]);
}

document.querySelector('#btn').addEventListener('click', clickHandler);

function clickHandler() {
    counter = (counter + 1) % 2;
    textNode.data = counter;
}
